package cn.edu.sdjzu.xg.kcsj.controller.basic;

import cn.edu.sdjzu.xg.kcsj.domain.CourseArrangement;
import cn.edu.sdjzu.xg.kcsj.service.CourseArrangementService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import util.JSONUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/updateCourseArrangement.ctl")
public class UpdateCourseArrangementController extends HttpServlet {
    @Override
    protected void doPut (HttpServletRequest req,HttpServletResponse resp) throws ServletException, IOException {
        JSONObject respMessage_jsonObj = new JSONObject ();
        resp.setContentType ("application/json;charset=UTF-8");
        String req_jsonStr = null;
        try {
            req_jsonStr = JSONUtil.getJSON (req);
        } catch (IOException e) {
            respMessage_jsonObj.put ("message","IOException");
            e.printStackTrace ();
        }
        JSONObject req_jsonObj = JSON.parseObject (req_jsonStr);
        if (req_jsonObj == null) {
            respMessage_jsonObj.put ("message","no have request");
        }
        CourseArrangement courseArrangement = req_jsonObj.toJavaObject (CourseArrangement.class);
        boolean update = false;
        try {
            update = CourseArrangementService.getInstance ().update(courseArrangement);
            if (update){
                respMessage_jsonObj.put ("message","update yes");
            }else {
                respMessage_jsonObj.put ("message","update no");
            }
        } catch (SQLException e) {
            respMessage_jsonObj.put ("message","sjk have exception");
            e.printStackTrace ();
        }
        try {
            resp.getWriter ().println (respMessage_jsonObj);
        } catch (IOException e) {
            e.printStackTrace ();
        }
    }
}
